package com.iis.gui;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import com.iis.entity.Orang;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Date;

public class FormKlien extends JInternalFrame {
	private JTextField textFieldNama;
	private JTextField textFieldTempatLahir;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					FormKlien frame = new FormKlien();
					
					
					
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public FormKlien() {
		setClosable(true);
		setTitle("Klien");
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout(0, 0));
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "Data Klien Baru", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(new GridLayout(10, 2));
		
		JLabel label = new JLabel("Nama");
		panel.add(label);
		
		textFieldNama = new JTextField();
		panel.add(textFieldNama);
		textFieldNama.setColumns(5);
		
		JLabel lblNewLabel = new JLabel("Tempat Lahir");
		panel.add(lblNewLabel);
		
		textFieldTempatLahir = new JTextField();
		panel.add(textFieldTempatLahir);
		textFieldTempatLahir.setColumns(5);
		
		JPanel panel_1 = new JPanel();
		JButton btnSimpan = new JButton("SIMPAN");
		btnSimpan.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				simpanOrang();
			}
		});
		getContentPane().add(panel_1, BorderLayout.SOUTH);
		panel_1.add(btnSimpan);
	}
	
	private void simpanOrang(){
		Orang newOrang = new Orang();
		newOrang.setNama(textFieldNama.getText());
		newOrang.setTempatLahir(textFieldTempatLahir.getText());
		newOrang.setTanggalLahir(new Date());
		newOrang.save();
	}

}
